﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Uinside.CreditSystem.DomainModels.Models
{
    public class Payment : BaseModel
    {
        private int _typeId;
        public int TypeId
        {
            get { return _typeId; }
            set { SetField(ref _typeId, value, "TypeId"); }
        }

        [NotMapped]
        public int Emergence
        {
            get
            {
                if (DateTime.Now >= this.ExpectDate)
                {
                    return 3;
                }

                var days = (DateTime.Now - this.RemindDate).Days;
                if (days >= 0)
                {
                    return 2;
                }
                return 1;
            }
        }

        private Setting _type;
        [ForeignKey("TypeId")]
        public virtual Setting Type
        {
            get { return _type; }
            set
            {
                SetField(ref _type, value, "Type");
            }
        }

        private int _lenderId;
        public int LenderId
        {
            get { return _lenderId; }
            set { SetField(ref _lenderId, value, "LenderId"); }
        }

        private Customer _lender;
        [ForeignKey("LenderId")]
        public virtual Customer Lender
        {
            get { return _lender; }
            set
            {
                SetField(ref _lender, value, "Lender");
            }
        }

        private int _borrowerId;
        public int BorrowerId
        {
            get { return _borrowerId; }
            set { SetField(ref _borrowerId, value, "BorrowerId"); }
        }

        private Customer _borrower;
        [ForeignKey("BorrowerId")]
        public virtual Customer Borrower
        {
            get { return _borrower; }
            set
            {
                SetField(ref _borrower, value, "Borrower");
            }
        }

        private decimal _sum;
        public decimal Sum
        {
            get { return _sum; }
            set
            {
                SetField(ref _sum, value, "Sum");
            }
        }

        private DateTime _expectDate;
        public DateTime ExpectDate
        {
            get { return _expectDate; }
            set
            {
                SetField(ref _expectDate, value, "ExpectDate");
            }
        }

        private DateTime? _paymentDate;
        public DateTime? PaymentDate
        {
            get { return _paymentDate; }
            set
            {
                SetField(ref _paymentDate, value, "PaymentDate");
            }
        }

        private DateTime _remindDate;
        public DateTime RemindDate
        {
            get { return _remindDate; }
            set
            {
                SetField(ref _remindDate, value, "RemindDate");
            }
        }

        private int _statusId;
        public int StatusId
        {
            get { return _statusId; }
            set { SetField(ref _statusId, value, "StatusId"); }
        }

        private Setting _status;
        [ForeignKey("StatusId")]
        public virtual Setting Status
        {
            get { return _status; }
            set
            {
                SetField(ref _status, value, "Status");
            }
        }

        private string _note;
        [StringLength(255)]
        public string Note
        {
            get { return _note; }
            set
            {
                SetField(ref _note, value, "Note");
            }
        }

        private ObservableCollection<Image> _certificateImages;
        public virtual ObservableCollection<Image> CertificateImages
        {
            get { return _certificateImages; }
            set
            {
                SetField(ref _certificateImages, value, "CertificateImages");
            }
        }

        private Order _order;
        [ForeignKey("OrderId")]
        public virtual Order Order
        {
            get { return _order; }
            set { SetField(ref _order, value, "Order"); }
        }

        private int? _orderId;
        public int? OrderId
        {
            get { return _orderId; }
            set { SetField(ref _orderId, value, "OrderId"); }
        }
    }
}
